package com.itheima.service.mongo.impl;

import com.itheima.domain.mongo.Sound;
import com.itheima.service.mongo.SoundService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

@DubboService
public class SoundServiceImpl implements SoundService {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void saveSound(Sound sound) {
        mongoTemplate.save(sound);
    }


    //查询语音
    @Override
    public Sound findBySoundId(Long id) {
        Query query = new Query(
                Criteria.where("userId").is(id)
        );

       return mongoTemplate.findOne(query, Sound.class);
    }

    // 查询所有
    @Override
    public List<Sound> findAll(Long userId) {
        Query query = new Query(
                Criteria.where("userId").ne(userId)
        );
        return mongoTemplate.find(query, Sound.class);
    }
}
